package org.mozhu.mboot.core.json;

import org.mozhu.mboot.core.json.jackson.DefaultObjectMapperConfigurer;
import org.mozhu.mboot.core.json.jackson.JSONHandlerJacksonProvider;
import org.mozhu.mboot.core.json.jackson.JacksonObjectMapperConfigurer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JSONAutoConfiguration {

    @Bean
    public JSON json(JSONHandlerProvider jsonHandlerProvider) {
        JSON json = JSON.get();
        json.setJsonHandlerProvider(jsonHandlerProvider);
        return json;
    }

    @Bean
    @ConditionalOnMissingBean
    public JacksonObjectMapperConfigurer objectMapperConfigurer() {
        return new DefaultObjectMapperConfigurer();
    }

    @Bean
    @ConditionalOnMissingBean
    public JSONHandlerProvider jsonHandlerProvider(JacksonObjectMapperConfigurer objectMapperConfigurer) {
        return new JSONHandlerJacksonProvider(objectMapperConfigurer);
    }

}
